﻿class Vertex
{
	public var x : Number;
	public var y : Number;
	public var z : Number;
	public var w : Number;
	public function Vertex (xx, yy, zz, ww)
	{
		if (xx == undefined)
		{
			xx = 0;
		}
		if (yy == undefined)
		{
			yy = 0;
		}
		if (zz == undefined)
		{
			zz = 0;
		}
		if (ww == undefined)
		{
			ww = 1;
		}
		x = xx;
		y = yy;
		z = zz;
		w = ww;
	}
	public static function Parse () : Vertex
	{
		if (arguments.length > 1)
		{
		} else
		{
			if (arguments.length == 0 || arguments == undefined)
			{
				return (new Vertex (0, 0, 0, 1));
			}
			var p = arguments [0];
			switch (typeof (p))
			{
				case "array" :
				if (p.length < 1)
				{
					say ("转换不成功 array.length<=0");
					return null;
				}
				var vertex : Vertex = new Vertex (Number (p [0]) , Number (p [1]) , Number (p [2]) , Number (p [3]));
				return vertex;
				break;
				case "object" :
				var a : Array = new Array ();
				for (var i in p)
				{
					if (i.indexOf ("x") != - 1)
					{
						a [0] = Number (p [i]);
					}
					if (i.indexOf ("y") != - 1)
					{
						a [1] = Number (p [i]);
					}
					if (i.indexOf ("z") != - 1)
					{
						a [2] = Number (p [i]);
					}
					if (i.indexOf ("w") != - 1)
					{
						a [3] = Number (p [i]);
					}
				}
				if (a.length <= 0)
				{
					say ("转换不成功 obj中没有x|y|z|w属性");
					return null;
				} else
				{
					return (Vertex.Parse (a));
				}
				break;
				case "string" :
				if (p.indexOf (",") != - 1)
				{
					var a : Array = new Array ();
					a = p.split (",");
					var vertex : Vertex = new Vertex (Number (a [0]) , Number (a [1]) , Number (a [2]) , Number (a [3]));
					return vertex;
				} else
				{
					var pp = eval (p);
					return (Vertex.Parse (pp));
				}
				break;
			}
		}
	}
	public function toString ()
	{
		say ("(" + x + "," + y + "," + z + "," + w + ")");
	}
	private static function say (o)
	{
		trace ("vertex:" + o);
	}
}
